package com.chuji.crmcj.act;

import android.content.Intent;
import android.view.View;
import android.widget.ExpandableListView;

import com.alibaba.fastjson.JSON;
import com.android.volley.Response;
import com.chuji.crmcj.R;
import com.chuji.crmcj.adapter.ExpandLvAdapter;
import com.chuji.crmcj.bean.BeforClientInfo;
import com.chuji.crmcj.utils.UIUtils;
import com.chuji.crmcj.utils.UrlUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by w.pitt on 2016/1/18.
 */
public class BeforeDataAct extends BaseActivity implements View.OnClickListener {

    private ExpandableListView mElvBefore;

    private List<String> mData = new ArrayList<String>();
    private View ll_left;
    private String customerID;

    @Override
    protected void initView() {
        setContentView(R.layout.act_before_deta);
        mElvBefore = (ExpandableListView) findViewById(R.id.elv_old_data);
        ll_left = findViewById(R.id.ll_left);
    }

    @Override
    protected void initData() {
        Intent intent = getIntent();
        customerID = intent.getStringExtra("CustomerID");
        mTvBarTitle.setText("历史资料");
        reqBefData();
    }

    private void reqBefData() {
        String strURL = String.format(UrlUtils.GETBEFRECORDDETAIL + "&CustomerID=%s", customerID);
        volleyRequest(strURL, new Response.Listener<String>() {
            @Override
            public void onResponse(final String s) {
                final BeforClientInfo beforClientInfo = JSON.parseObject(s, BeforClientInfo.class);
                UIUtils.runInMainThread(new Runnable() {
                    @Override
                    public void run() {
                        ExpandLvAdapter expandLvAdapter = new ExpandLvAdapter(UIUtils.getContext(), beforClientInfo, mElvBefore);
                        mElvBefore.setAdapter(expandLvAdapter);
                    }
                });
            }
        });
    }

    @Override
    protected void initListener() {
        ll_left.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_left:
                finish();
                break;
        }
    }
}
